package convertor

import (
	"ginfwk/domain/model/entity"
	"ginfwk/infrastructure/do"
	"ginfwk/infrastructure/helper/gslice"
)

type UserConvertor struct {
}

func (c *UserConvertor) ToUserDO(user *entity.UserEntity) (userDO *do.UserDO) {
	if user == nil {
		return nil
	}
	return &do.UserDO{
		Id:        user.Id,
		Name:      user.Name,
		Age:       user.Age,
		Address:   user.Address,
		CreatedAt: user.CreatedAt,
		UpdatedAt: user.UpdatedAt,
	}
}

func (c *UserConvertor) ToUserDOList(users []*entity.UserEntity) []*do.UserDO {
	return gslice.MapList(c.ToUserDO, users)
}

func (c *UserConvertor) ToUserEntity(userDO *do.UserDO) *entity.UserEntity {
	if userDO == nil {
		return nil
	}
	return &entity.UserEntity{
		Id:        userDO.Id,
		Name:      userDO.Name,
		Age:       userDO.Age,
		Address:   userDO.Address,
		CreatedAt: userDO.CreatedAt,
		UpdatedAt: userDO.UpdatedAt,
	}
}

func (c *UserConvertor) ToUserEntityList(userDOs []*do.UserDO) []*entity.UserEntity {
	return gslice.MapList(c.ToUserEntity, userDOs)
}
